//
//  LKPictureDeleteOrAddCell.m
//  YLHelper
//
//  Created by she1323 on 2018/5/31.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKPictureDeleteOrAddCell.h"
@interface LKPictureDeleteOrAddCell ()<HXPhotoViewDelegate>

@end
@implementation LKPictureDeleteOrAddCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self addSubview:self.photoView];
}
-(void)setModel:(LKPictureDeleteOrAddModel *)model{
    _model = model;
    [self.manager changeAfterCameraArray:model.endCameraList];
    [self.manager changeAfterCameraPhotoArray:model.endCameraPhotos];
    [self.manager changeAfterCameraVideoArray:model.endCameraVideos];
    [self.manager changeAfterSelectedCameraArray:model.endSelectedCameraList];
    
    [self.manager changeAfterSelectedCameraPhotoArray:model.endSelectedCameraPhotos];
    
    [self.manager changeAfterSelectedCameraVideoArray:model.endSelectedCameraVideos];
    [self.manager changeAfterSelectedArray:model.endSelectedList];
    [self.manager changeAfterSelectedPhotoArray:model.endSelectedPhotos];
    [self.manager changeAfterSelectedVideoArray:model.endSelectedVideos];
    [self.manager changeICloudUploadArray:model.iCloudUploadArray];
    [self.photoView refreshView];
}

- (void)photoView:(HXPhotoView *)photoView changeComplete:(NSArray<HXPhotoModel *> *)allList photos:(NSArray<HXPhotoModel *> *)photos videos:(NSArray<HXPhotoModel *> *)videos original:(BOOL)isOriginal {

    self.model.endCameraList = self.manager.afterCameraArray.mutableCopy;
    self.model.endCameraPhotos = self.manager.afterCameraPhotoArray.mutableCopy;
    self.model.endCameraVideos = self.manager.afterCameraVideoArray.mutableCopy;
    self.model.endSelectedCameraList = self.manager.afterSelectedCameraArray.mutableCopy;
    self.model.endSelectedCameraPhotos = self.manager.afterSelectedCameraPhotoArray.mutableCopy;
    self.model.endSelectedCameraVideos = self.manager.afterSelectedCameraVideoArray.mutableCopy;
    self.model.endSelectedList = self.manager.afterSelectedArray.mutableCopy;
    
    NSLog(@"选中之后%@",self.model.endSelectedList);
    self.model.endSelectedPhotos = self.manager.afterSelectedPhotoArray.mutableCopy;
    self.model.endSelectedVideos = self.manager.afterSelectedVideoArray.mutableCopy;
    self.model.iCloudUploadArray = self.manager.afterICloudUploadArray.mutableCopy;
}
- (void)photoView:(HXPhotoView *)photoView updateFrame:(CGRect)frame {
    if (frame.size.height == self.model.photoViewHeight) {
        return;
    }
    self.model.photoViewHeight = frame.size.height;
    if (self.photoViewChangeHeightBlock) {
        self.photoViewChangeHeightBlock(self);
    }
}
- (HXPhotoManager *)manager {
    if (!_manager) {
        _manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo];
//        _manager.configuration.showDeleteNetworkPhotoAlert = NO;
//        _manager.configuration.saveSystemAblum = YES;
//        _manager.configuration.photoMaxNum = 9; //
//        _manager.configuration.videoMaxNum = 5;  //
//        _manager.configuration.maxNum = 14;
    }
    return _manager;
}
- (HXPhotoView *)photoView {
    if (!_photoView) {
        _photoView = [[HXPhotoView alloc] initWithFrame:CGRectMake(12, 0, [UIScreen mainScreen].bounds.size.width - 24, 0) WithManager:self.manager];
        _photoView.backgroundColor = [UIColor whiteColor];
        _photoView.delegate = self;
        
    }
    return _photoView;
}
//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//
//    // Configure the view for the selected state
//}

@end
